import React from 'react'
import { Box } from '$components';
import { useFsRequest } from '$utils';
import { mathRound } from './util'
function AccessData() {

    const { data: accessdata = [] } = useFsRequest({
        url: 'homepage/accessdata',
        pollingInterval: 1000 * 60,
        cacheKey: 'accessdata',
    });


    const renderBody = () => {
        return <div className='access_data'>
            <div className='_img'></div>
            <div className='data_unit'>
                数据单位<div className='data_number'>{!accessdata?.projects ? '-' : accessdata?.projects?.split(',')?.length}</div>个
            </div>
            <div className='data_today'>
                今日数据<div className='data_number'>{!accessdata?.res?.stat?.today ? '-' : accessdata?.res?.stat?.today > 1000 ? mathRound(accessdata?.res?.stat?.today) : accessdata?.res?.stat?.today}</div>{accessdata?.res?.stat?.today > 1000 ? '万条' : '条'}
            </div>
            <div className='data_total'>
                数据总量<div className='data_number'>{accessdata?.res?.stat?.datas ? Math.round(accessdata?.res?.stat?.datas / 10000) : '-'}</div>万条
            </div>
        </div>
    }

    return <Box title={"接入数据统计"} >
        {renderBody()}
    </Box>
}

export default AccessData;


